using System;

using OpenXmlWriter.Packaging;

namespace OpenXmlWriter.Packaging
{
	public class ThemePart : OpenXmlPart
	{
    private const string PartRelationshipType =
      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";

    private const string PartName = "theme";
    private const string PartPath = "word/theme";
    private const string PartExtension = ".xml";
    public const string PartContentType = "application/vnd.openxmlformats-officedocument.theme+xml";
    private string _targetPath;

    public override void Initialize(OpenXmlPackage openXmlPackage, OpenXmlPartContainer openXmlPartContainer)
    {
      base.Initialize (openXmlPackage, openXmlPartContainer);
      _targetPath = CreateUniquePath();
      _contentType = new ContentType(_targetPath, PartContentType, false);
    }

    private string CreateUniquePath()
    {
      return PartPath + "/" + PartName + PartExtension;
    }

	  public override string RelationshipType
	  {
	    get
	    {
	      return PartRelationshipType;
	    }
	  }

	  public override ContentType ContentType
	  {
	    get
	    {
	      return _contentType;
	    }
	  }

	  public override void AddTo(OpenXmlPartCollection parts)
	  {
      if (parts.ContainsKey(_targetPath))
      {
        throw new InvalidOperationException();
      }

      parts.Add(_targetPath, this);
	  }

	  public override string TargetPath
	  {
	    get
	    {
	      return _targetPath;
	    }
	  }
	}
}
